package com.exam.xiecheng;

import java.util.HashMap;
import java.util.Scanner;

/**
 * date:
 * description:
 */
public class Solution003 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int len = scanner.nextInt();
        int k = scanner.nextInt();
        String str = scanner.next().trim();
        int start = 0, end = 0;
        HashMap<Character, Integer> map = new HashMap<>();
        int ans = 0;
        while (end < len){
            while(end < len && (map.size() < k || map.containsKey(str.charAt(end)))){
                char ch = str.charAt(end);
                map.put(ch, map.getOrDefault(ch, 0) + 1);
                end++;
            }
            ans = Math.max(ans, end - start);
            while(start < end && (map.size() >= k)){
                char ch = str.charAt(start);
                map.put(ch, map.get(ch) - 1);
                if(map.get(ch) == 0){
                    map.remove(ch);
                }
                start++;
            }
        }
        System.out.println(ans);

    }
}
